﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BLL;
using Model;

namespace Sales
{
    public partial class frmJyhf : Form
    {
        private TempStorageBLL tempStorageBLL;
        private static frmJyhf jyhf = null;

        private static DataTable tempData = null;

        public frmJyhf()
        {
            InitializeComponent();
           this.label1.Font = new Font("宋体", 13, FontStyle.Bold);

           SetdataGridStyle();
           BindData("");

        }
        public static frmJyhf CreateInstance()
        {
            if (null == jyhf)
            {
                jyhf = new frmJyhf();
            }
            return jyhf;
        }

        private void frmJyhf_Load(object sender, EventArgs e)
        {

        }

        private void gbtnCx_Click(object sender, EventArgs e)
        {
       
            string start = this.dateTime.Value.ToString("yyyy-MM-dd") + " 00:00:00";
            string end = this.dateTime.Value.ToString("yyyy-MM-dd") + " 23:59:59";
            string strWhere = "   (temptime>='" + start + "' and temptime<='" + end + "')";
            BindData(strWhere);
        }
        private void BindData(string strWhere)
        {
            tempStorageBLL = new TempStorageBLL();
            DataTable dt = tempStorageBLL.GetTempStorageData(strWhere);

            //获取一个表格式
            if (tempData == null && dt != null)
                tempData = dt.Clone();


            if (dt != null)
                this.dataGridView1.DataSource = dt;
            else
                this.dataGridView1.DataSource = tempData;
        }
        /// <summary>
        /// 样式
        /// </summary>
        /// <param name="dt"></param>
        private void SetdataGridStyle()
        {

            try
            {
                this.dataGridView1.RowHeadersVisible = false;
                //暂存流水号
                DataGridViewTextBoxColumn dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "暂存流水号";
                dc.DataPropertyName = "tempDjh";
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[0].Width = 90;
                this.dataGridView1.Columns[0].ReadOnly = true;

                //客户编号
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "客户编号";
                dc.DataPropertyName = "khbh";

                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[1].Width = 110;
                this.dataGridView1.Columns[1].ReadOnly = true;

                //客户名称
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "客户名称";
                dc.DataPropertyName = "khmc";

                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[2].Width = 110;
                this.dataGridView1.Columns[2].ReadOnly = true;

                //营业员编号
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "营业员编号";
                dc.DataPropertyName = "Yyybh";

                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[3].Width = 110;
                this.dataGridView1.Columns[3].ReadOnly = true;

                //营业员名称
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "营业员名称";
                dc.DataPropertyName = "Yyymc";

                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[4].Width = 110;
                this.dataGridView1.Columns[4].ReadOnly = true;

                //数量
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "数量";
                dc.DataPropertyName = "Sl";
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[5].Width = 110;
                this.dataGridView1.Columns[5].ReadOnly = true;

                //金额
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "金额";
                dc.DataPropertyName = "je";
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[6].Width = 110;
                this.dataGridView1.Columns[6].ReadOnly = true;

                //暂存时间
                dc = new DataGridViewTextBoxColumn();
                dc.HeaderText = "暂存时间";
                dc.DataPropertyName = "temptime";
                dataGridView1.Columns.Add(dc);
                this.dataGridView1.Columns[7].Width = 110;
                this.dataGridView1.Columns[7].ReadOnly = true;
            }
            catch { }
        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {

            TempStorageH tempStorageH = new TempStorageH();
            int index = this.dataGridView1.CurrentRow.Index;

            string tempDjh = this.dataGridView1.Rows[index].Cells[0].Value.ToString();
            string khbh = this.dataGridView1.Rows[index].Cells[1].Value.ToString();
            string khmc = this.dataGridView1.Rows[index].Cells[2].Value.ToString();
            string yyybh = this.dataGridView1.Rows[index].Cells[3].Value.ToString();
            string yyymc = this.dataGridView1.Rows[index].Cells[4].Value.ToString();
            string sl = this.dataGridView1.Rows[index].Cells[5].Value.ToString();
            string je = this.dataGridView1.Rows[index].Cells[6].Value.ToString();
            string temptime = this.dataGridView1.Rows[index].Cells[7].Value.ToString().Replace('*', ':');
            tempStorageH.tempDjh = int.Parse(tempDjh);
            tempStorageH.Khbh = khbh;
            tempStorageH.Khmc = khmc;
            tempStorageH.Yyybh = yyybh;
            tempStorageH.Yyymc = yyymc;
            tempStorageH.Sl = int.Parse(sl);
            tempStorageH.Je = decimal.Parse(je);
            tempStorageH.TempTime = temptime;



            if (tempDjh != "")
            {
                string tempseri = Common.Serialize(tempStorageH);
                frmMain main = frmMain.CreateInstance();
                MiddleModule.SendMessage(this, main, tempseri);
                jyhf = null;
                this.Close();
            }
            else
            {
                Message.MsgBoxInfo("请选择商品记录！");
            }


        }


   
    }
}
